#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <iostream>
#include <pthread.h>
#include <mutex>
using namespace std;

class CWiFi
{
public:
    CWiFi(string server_addr,const int port);
    ~CWiFi();
    void start();
    bool is_opened();
    static void * connectServer(void *arg);
    int sendData(char *data,int length);
    int recvData(char *data,int length);
    static void * detectState(void *arg);

private:
    bool isOpened;
    int sockfd;
    struct sockaddr_in servaddr;
    pthread_t connect_thread;
    pthread_t detect_thread;
    mutex mu;

    int keepAlive; // 开启keepalive属性
    int keepIdle; // 如该连接在3秒内没有任何数据往来,则进行探测 
    int keepInterval; // 探测时发包的时间间隔为3 秒
    int keepCount; // 探测尝试的次数.如果第1次探测包就收到响应了,则后2次的不再发.

};